package com.bfm.ioc;

import com.bfm.annotation.Autowired;
import com.bfm.core.BeanContainer;

import java.lang.reflect.Field;

/**
 * @author slm
 * @Description: TODO
 * @Date 2019/12/14
 **/
public class Ioc {

    private BeanContainer beanContainer;

    public Ioc() {
        beanContainer = BeanContainer.getInstance();
    }

    public void doIoc() {
        for (Class<?> clz : beanContainer.getClasses()) {
            final Object bean = beanContainer.getBean(clz);
            Field[] declaredFields = clz.getDeclaredFields();
            for (Field field : declaredFields) {
                if (field.isAnnotationPresent(Autowired.class)) {
                    final Class<?> fieldClass = field.getType();

                }
            }
        }
    }

    private Object getClassInstance(final Class<?> clz) {
//        return Optional.ofNullable(beanContainer.getBean(clz))
//                .orElseGet(() -> {
//
//                })
        return null;
    }

    private Class<?> getImplementClass(final Class<?> interfaceClass) {
        return beanContainer.getClassesBySuper(interfaceClass)
                .stream()
                .findFirst()
                .orElseGet(null);
    }
}
